

from util import ReadFile, WriteFile
from xyztools import extractXYZLine
import datetime

def nrnScale(srcFilename, sinkFilename, scaleFactor):
    datestr = datetime.datetime.now().strftime("%d-%B-%Y")
    # Find the amount of translation we need to do!
    data = ReadFile(srcFilename)
    dataLines = [l for l in data.split("\n") if l.strip() and not l.strip().startswith("#") ]
    CommentLines = [l for l in data.split("\n") if l.strip() and l.strip().startswith("#") ]

    outData = CommentLines + ["# Corrected for shrinkage (x1.28) using nrnScaled.py" + " On: %s"%datestr]
    for l in dataLines:
        i,t,x,y,z,X,Y,Z,p = extractXYZLine(l)
        x *= scaleFactor
        y *= scaleFactor
        z *= scaleFactor
        
        X *= scaleFactor
        Y *= scaleFactor
        Z *= scaleFactor
        
        outData.append( "\t".join( [str(g) for g in [i,t,x,y,z,X,Y,Z,p] ] ) )
    WriteFile( sinkFilename, "\n".join( outData) )
    
